public class Test10 {
    public static int numberofone(int n){
        int res =0;
        while(n!=0){
            res += (n&1);
            n >>>= 1;
        }
        return  res;
    }
    public static  int numberofone1(int n){
        int res = 0;
        while(n!=0){
            res ++;
            n = (n-1)&n;
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(numberofone(0B00000000_00000000_00000000_00000000)); // 0
        System.out.println(numberofone(0B00000000_00000000_00000000_00000001)); // 1
        System.out.println(numberofone(0B11111111_11111111_11111111_11111111)); // -1
        System.out.println(0B01111111_11111111_11111111_11111111 == Integer.MAX_VALUE);
        System.out.println(numberofone(0B01111111_11111111_11111111_11111111)); // Integer.MAX_VALUE
        System.out.println(0B10000000_00000000_00000000_00000000 == Integer.MIN_VALUE);
        System.out.println(numberofone(0B10000000_00000000_00000000_00000000)); // Integer.MIN_VALUE

        System.out.println("");
        System.out.println(numberofone1(0B00000000_00000000_00000000_00000000)); // 0
        System.out.println(numberofone1(0B00000000_00000000_00000000_00000001)); // 1
        System.out.println(numberofone1(0B11111111_11111111_11111111_11111111)); // -1
        System.out.println(numberofone1(0B01111111_11111111_11111111_11111111)); // Integer.MAX_VALUE
        System.out.println(numberofone1(0B10000000_00000000_00000000_00000000)); // Integer.MIN_VALU
    }

}
